//
//  ZRHomeTableViewCell.m
//  SinaByOC
//
//  Created by 张锐 on 16/3/19.
//  Copyright © 2016年 zhangr. All rights reserved.
//


#import <Masonry.h>
#import "ZRHomeTableViewCell.h"
#import "ZROriginal.h"
#import "ZRBottom.h"
#import "ZRRetweet.h"

@interface ZRHomeTableViewCell()

@property (nonatomic,strong) ZROriginal * original;

@property (nonatomic,strong) ZRBottom * bottom;

@property (nonatomic,strong) ZRRetweet * retweet;

@property (nonatomic,strong) MASConstraint * constraint;

@end

@implementation ZRHomeTableViewCell

-(void)setHomeCellModel:(ZRHomeCellModel *)homeCellModel{

    _homeCellModel = homeCellModel;
    
    self.original.homeCellModel = homeCellModel;
    
    self.bottom.homeCellModel = homeCellModel;
    

     [self.constraint uninstall];
    
    if (homeCellModel.retweeted_status == nil) {
        
        self.retweet.hidden = YES;
        
       
        
        [self.bottom mas_updateConstraints:^(MASConstraintMaker *make) {
           
           self.constraint =
            make.top.equalTo(self.original.mas_bottom).offset(6);
            
        }];
    }
    else{
    
        self.retweet.hidden = NO;
        
        self.retweet.homeCellModel = homeCellModel;
        
        [self.bottom mas_updateConstraints:^(MASConstraintMaker *make) {
        
            self.constraint =
            make.top.equalTo(self.retweet.mas_bottom).offset(6);
            
        }];
    
    }
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self setupUI];
        
    }
    return self;
}
-(void)setupUI{
    
    [self addSubview:self.original];
    [self addSubview:self.bottom];
    [self addSubview:self.retweet];
    
    [self.original mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.mas_top);
        
        make.left.equalTo(self.mas_left);
        
        make.right.equalTo(self.mas_right);
        
//        make.bottom.equalTo(self.mas_bottom);
    }];
    
    [self.bottom mas_makeConstraints:^(MASConstraintMaker *make) {
    
        self.constraint = make.top.equalTo(self.retweet.mas_bottom).offset(6);
        
        make.left.equalTo(self.mas_left);
        
        make.right.equalTo(self.mas_right);
        
        make.height.equalTo(@30);
        
        make.bottom.equalTo(self.mas_bottom);
        
    }];
    
    [self.retweet mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.original.mas_bottom);
        
        make.left.equalTo(self.mas_left);
        
        make.right.equalTo(self.mas_right);
        
    }];
    
    


}
//懒加载
-(ZROriginal *)original{

    if (_original == nil) {
        
        _original = [[ZROriginal alloc]init];
        
    }
    return _original;

}
-(ZRBottom *)bottom{

    if (_bottom == nil) {
        
        _bottom = [[ZRBottom alloc]init];
    }

    return _bottom;
}
-(ZRRetweet *)retweet{

    if (_retweet == nil) {
        
        _retweet = [[ZRRetweet alloc]init];
    }

    return _retweet;
}

@end
